<?php
/**
 * Created by program.
 * Description:评论管理
 * User: sunnier
 * Email: xiaoyao_xiao@126.com
 * Date: 2020-11-18
 * Time: 14:39
 */
namespace app\api\controller;

class Comment extends Base
{
    protected $commentService;

    public function initialize()
    {
        parent::initialize();

        $this->commentService=app('app\common\service\CommentService');
    }

    /**
     * @return \think\response\Json
     * Description:评论列表
     * Author:sunnier
     * Email:xiaoyao_xiao@126.com
     * 2020-11-18 14:39
     */
    public function index(){
        $postData=input('get.');
        if(!empty($postData['page'])) {
            $page = $postData['page'];
        }else{
            $page=1;
        }
        if(!empty($postData['per_page'])) {
            $listRow = $postData['per_page'];
        }else{
            $listRow=10;
        }
        $blackId=$postData['id'];
        $result=$this->commentService->getList(['black_id'=>$blackId],$page,$listRow);
        return api_res($result['status'],$result['msg'],$result['data']);
    }

    /**
     * @return \think\response\Json
     * Description:提交评论
     * Author:sunnier
     * Email:xiaoyao_xiao@126.com
     * 2020-11-27 12:31
     */
    public function addComment(){
        $postData=input('post.');
        $result=$this->commentService->addComment($postData);
        return api_res($result['status'],$result['msg'],$result['data']);
    }
}